<!--
 * @Author: wu07 1732042133@qq.com
 * @Date: 2023-01-14 15:25:58
 * @LastEditors: wu07 1732042133@qq.com
 * @LastEditTime: 2023-02-02 10:43:38
 * @FilePath: \recruitAPP\recruitApp\recruitApp\src\pages\login\Verify.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<!-- 视图层 -->
<template>
  <van-nav-bar
    title="设置密码"
    left-text="返回"
    left-arrow
    @click-left="onClickLeft"
  />
  <van-tabs v-model:active="active" title-active-color="#0079FE" color="#fff">
    <van-tab title="1.验证手机号码" disabled> </van-tab>
    <van-tab title="2.设置新密码">
      <van-form @submit="onSubmit">
        <van-cell-group inset>
          <van-field
            v-model="password"
            left-icon="manager-o"
            name="password"
            type="password"
            placeholder="请设置6-20位新的登录密码"
            :rules="[{ required: true, message: '请填写新密码' }]"
          />
          <van-field
            v-model="passwordT"
            type="password"
            left-icon="manager-o"
            name="passwordT"
            placeholder="请再次输入新的登录密码"
            :rules="[{ required: true, message: '请填写新密码' }]"
          >
          </van-field>
        </van-cell-group>
        <div style="margin: 16px">
          <van-button round block type="primary" native-type="submit">
            提交
          </van-button>
        </div>
      </van-form>
    </van-tab>
  </van-tabs>
</template>
<!-- 逻辑层 -->
<script setup>
import { get, post, put, del } from "~/axios/http";
import { showDialog } from "vant";
import { ref, reactive } from "vue";
// 导入useRouter方法
import { useRouter, useRoute } from "vue-router";
const router = useRouter();
const route = useRoute();
// 返回上一页
const onClickLeft = () => {
  router.go(-1);
};
// 表单

const password = ref("");
const passwordT = ref("");
async function onSubmit(values) {
  let data = reactive({
    id: route.query.id,
  });
  if (values.password.length < 6 && values.passwordT.length < 6) {
    showDialog({
      title: "提示",
      message: "密码不低于六位",
    });
  } else if (values.password == values.passwordT) {
    let res2 = await get(`/api/infomation/${data.id}`);
    let res = await put(`/api/infomation/${data.id}`, {
      password: values.password,
      iphone: res2.data.iphone,
    });
    showDialog({
      title: "提示",
      message: "修改成功",
    });
    router.push("/login");
  } else {
    showDialog({
      title: "提示",
      message: "两次密码不一致",
    });
  }
}
</script>
<!-- 样式层 -->
<style  scoped>
</style>